//
//  SEGMyProfileManager.m
//  ExcellentHome
//
//  Created by 刘山 on 2017/1/13.
//  Copyright © 2017年 陈区. All rights reserved.
//

#import "SEGMyProfileManager.h"

@implementation SEGMyProfileManager

// 保存房屋信息
-(void)requestSaveUserHouse:(NSString*)houseID Finished:(SEGNetworkRequestCallBack)finished{
    
    NSDictionary *params = @{
                             @"houseId":[SEGUtils ValueToString:houseID] //房屋id
                             };
    
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/",kUhomecp_app,@"/userInfo/saveUserHouse.json",nil];
    [SEGHTTPBusinessManager seg_requestWithMethod:POST URLString:urlString parameters:params finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
        finished(result,nil);
    }];
}

// 单元房屋列表接口
-(void)requestQueryHouseByUnitBuildingID:(NSString*)buildId
                                Finished:(SEGRequestCallBack)finished{
    
    NSDictionary *params = @{
                             @"buildId":[SEGUtils ValueToString:buildId]     //楼栋id
                             };
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/",kUhomecp_app,@"/userInfo/queryUnitByBuildId.json",nil];
    [SEGHTTPBusinessManager seg_requestWithMethod:GET URLString:urlString parameters:params finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
        if (!isSuccessed) {
            finished(NO, codeType, errorMessage);
            return;
        }
        
        NSArray *dataArray = [result valueForKey:@"data"];
        if (!dataArray || ![dataArray isKindOfClass:[NSArray class]]) {
            finished(NO, codeType, errorMessage);
            return;
        }
        NSMutableArray *arrM = [NSMutableArray array];
        for (NSDictionary *dic in dataArray) {
            SEGUnitByBuildIdModel *model = [SEGUnitByBuildIdModel initWithDictionary:dic];
            [arrM addObject:model];
        }
        self.seg_segunitbybuildidmodel = [arrM copy];
        finished(YES, codeType, errorMessage);

    }];
}

//请求小区内所有房号列表
-(void)requestQueryHouseByParans:(NSDictionary*)params Finished:(SEGRequestCallBack)finished{
    
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/",kUhomecp_app,@"/userInfo/queryHouseByUnitById.json",nil];
    [SEGHTTPBusinessManager seg_requestWithMethod:GET URLString:urlString parameters:params finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
        if (!isSuccessed) {
            finished(NO, codeType, errorMessage);
            return;
        }
        
        NSArray *dataArray = [result valueForKey:@"data"];
        if (!dataArray || ![dataArray isKindOfClass:[NSArray class]]) {
            finished(NO, codeType, errorMessage);
            return;
        }
        NSMutableArray *arrM = [NSMutableArray array];
        for (NSDictionary *dic in dataArray) {
            SEGHouseByUnitModel *model = [SEGHouseByUnitModel initWithDictionary:dic];
            [arrM addObject:model];
        }
        self.seg_seghousebyunitmodel = [arrM copy];
        finished(YES, codeType, errorMessage);
    }];
}

//请求查询项目下辖楼栋列表
-(void)requestBuildingListBycommunityId:(NSString *)communityId Finished:(SEGRequestCallBack)finished{
    NSDictionary *params = @{
                             @"communityId":[SEGUtils ValueToString:communityId]     //小区id
                             };
    
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/",kUhomecp_app,@"/userInfo/getCommunityBuildList.json",nil];
    [SEGHTTPBusinessManager seg_requestWithMethod:GET URLString:urlString parameters:params finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
        
        if (!isSuccessed) {
            finished(NO, codeType, errorMessage);
            return;
        }
        
        NSArray *dataArray = [result valueForKey:@"data"];
        if (!dataArray || ![dataArray isKindOfClass:[NSArray class]]) {
            finished(NO, codeType, errorMessage);
            return;
        }
        NSMutableArray *arrM = [NSMutableArray array];
        for (NSDictionary *dic in dataArray) {
            SEGCommunityBuildListModel* model = [SEGCommunityBuildListModel initWithDictionary:dic];
            [arrM addObject:model];
        }
        self.seg_segcommunitybuildlistmodel = [arrM copy];
        
        finished(YES, codeType, errorMessage);
        
    }];
}

#pragma mark - getter
- (NSArray<SEGCommunityBuildListModel*>*)seg_segcommunitybuildlistmodel
{
    if (!_seg_segcommunitybuildlistmodel)
    {
        _seg_segcommunitybuildlistmodel = [NSArray array];
    }
    return _seg_segcommunitybuildlistmodel;
}

- (NSArray<SEGUnitByBuildIdModel*>*)seg_segunitbybuildidmodel
{
    if (!_seg_segunitbybuildidmodel)
    {
        _seg_segunitbybuildidmodel = [NSArray array];
    }
    return _seg_segunitbybuildidmodel;
}

- (NSArray<SEGHouseByUnitModel*>*)seg_seghousebyunitmodel
{
    if (!_seg_seghousebyunitmodel)
    {
        _seg_seghousebyunitmodel = [NSArray array];
    }
    return _seg_seghousebyunitmodel;
}


@end
